﻿String.prototype.Trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
$(document).ready(function() {
    $("#ctl00_MainContent_cbJcxs_0").bind("click", function() {
        if ($(this).attr("checked") != "") {
            $("#ctl00_MainContent_cbJcxs_1").removeAttr("checked");
        }
    })
    $("#ctl00_MainContent_cbJcxs_1").bind("click", function() {
        if ($(this).attr("checked") != "") {
            $("#ctl00_MainContent_cbJcxs_0").removeAttr("checked");
        }
    })
    $("#ctl00_MainContent_cbDwxz_0").bind("click", function() {
        if ($(this).attr("checked") != "") {
            $("#ctl00_MainContent_cbDwxz_1").removeAttr("checked");
        }
    })
    $("#ctl00_MainContent_cbDwxz_1").bind("click", function() {
        if ($(this).attr("checked") != "") {
            $("#ctl00_MainContent_cbDwxz_0").removeAttr("checked");
        }
    })
    $("input[type='checkbox'][id^='cb_tb']").each(function() {
        $(this).bind("click", function() {
            var id = $(this).attr("id");
            if ($(this).attr("checked") != "") {
                $("input[type='text'][id$='" + id.substr(5, 8) + "']").val($(this).attr("value"));
                $("input[type='checkbox'][key='tb" + id.substr(5, 8) + "']").each(function() {
                    if ($(this).attr("id") != id) {
                        $(this).removeAttr("checked");
                    }
                });
            }
            else {
                $("input[type='text'][id$='" + id.substr(5, 8) + "']").val("");
            }
            var val = document.getElementById("ctl00_MainContent_panel_tb" + id.substr(5, 8));
            val.style.display = "none";
        });
    });

    $("#ctl00_MainContent_cb010301").bind("click", function() {
        if ($(this).attr("checked") != "") {
            $("#ctl00_MainContent_cb010302").removeAttr("checked");
        }
    });
    $("#ctl00_MainContent_cb010302").bind("click", function() {
        if ($(this).attr("checked") != "") {
            $("#ctl00_MainContent_cb010301").removeAttr("checked");
        }
    });

    if ($("#ctl00_MainContent_HiddenField1").val().toString().Trim() == "") {
        $("#ctl00_MainContent_btnAdd").removeAttr("onclick");
        $("#ctl00_MainContent_btnAdd").bind("click", function() {
//            var yazheng = false;
//            $("input[type='checkbox'][id^='ctl00_MainContent_pcqkflcbl']").each(function() {
//                if ($(this).attr("checked") != "") {
//                    yazheng = true;
//                }
//            });
//            if (yazheng == false) {
//                alert("请选择建筑、单位、场所类型！");
//                return yazheng;
//            }
            if ($("#ctl00_MainContent_cbhg").attr("checked") == ""
        && $("#ctl00_MainContent_cbbhg").attr("checked") == "") {
                alert("请选择检查结果！");
                return false;
            }
            if (TimeControl() == false) {
                return false;
            };
            if (typeof (Page_ClientValidate) == 'function') {
                if (Page_ClientValidate() == false || allLength() == false) {
                    return false;
                }
            };
            $(this).attr("disabled", "disabled");
            var txtJcTime = $("#ctl00_MainContent_txtJcTime").val().replace("年", "-").replace("月", "-").replace("日", " ");
            var txtJcqshour = $("#ctl00_MainContent_txtJcqshour").val();
            var txtJcqsminute = $("#ctl00_MainContent_txtJcqsminute").val();
            var txtJcjshour = $("#ctl00_MainContent_txtJcjshour").val();
            var txtJcjsminute = $("#ctl00_MainContent_txtJcjsminute").val();

            $.getJSON("../../XTWHPage/CYDWPage/AjaxTreeList.ashx", {
                'JcqsTime': txtJcTime + txtJcqshour + ':' + txtJcqsminute + ':00',
                'JcjsTime': txtJcTime + txtJcjshour + ':' + txtJcjsminute + ':00',
                'JcinTime': $("#ctl00_MainContent_HiddenField2").val()
            }, function(json) {
                $.each(json, function(i, n) {
                    if (n.toString() == "false") {
                        popWin('超时原因');
                        $("#chaoMessage").val($("#ctl00_MainContent_HiddenField1").val());
                    }
                    else if (n.toString() == "true") {
                        $("#ctl00_MainContent_HiddenField1").val("");
                        //ajaxyzwh();
                        __doPostBack('ctl00$MainContent$btnAdd', '');
                    }
                    else if (n.toString() == "1") {
                        alert("请录入正确的时间格式");
                        $("#ctl00_MainContent_btnAdd").removeAttr("disabled");
                    }
                    else {
                        alert("检查结束时间必须大于检查起始时间(时间为24小时制)");
                        $("#ctl00_MainContent_btnAdd").removeAttr("disabled");
                    }
                });
            });
            return false;
        });
    }
//    $("#ctl00_MainContent_txtJcTime").bind("change", function() {
//        dpccheck();
//    });
//    dpccheck();
});

function dpccheck() {
    var txtJcTime = $("#ctl00_MainContent_txtJcTime").val().replace("年", "-").replace("月", "-").replace("日", " ");
    var jcsj = new Date(txtJcTime.split('-')[0], txtJcTime.split('-')[1], txtJcTime.split('-')[2]);
    var xdsj = new Date(2011, 10, 1);
    if (jcsj >= xdsj) {
        $("#dpcspan").hide();
        $("input[type='checkbox'][id^='ctl00_MainContent_pcqkflcbl']").each(function() {
            $(this).removeAttr("disabled");
        });
    }
    else {
        $("#dpcspan").show();
        $("input[type='checkbox'][id^='ctl00_MainContent_pcqkflcbl']").each(function() {
            $(this).removeAttr("checked");
            $(this).attr("disabled", "disabled");
        });
    }
}

function Getbh(p1, p2) {
    var obj = document.getElementById("ctl00_MainContent_" + p2);
    var WinElementPos = getWinElementPos(obj);
    var val = document.getElementById("ctl00_MainContent_" + p1);
    val.style.display = "inline";
    val.style.left = (parseInt(WinElementPos.x)).toString() + "px";
    val.style.top = (parseInt(WinElementPos.y) + 15).toString() + "px";
    $("div[id^='ctl00_MainContent_panel_tb']").each(function() {
        if ($(this).attr("id") != ("ctl00_MainContent_" + p1)) {
            $(this).css("display", "none");
        }
    });
    setTimeout("yincan('ctl00_MainContent_" + p1 + "')", 5000);
}
function yincan(p1) {
    var val = document.getElementById(p1);
    val.style.display = "none";
}
function postform() {

    if ($("#chaoMessage").val().toString().Trim() == "") {
        alert("请填写超时原因");
    }
    else {
        if ($("#chaoMessage").val().toString().length > 100) {
            alert("超时原因不超过100个字");
        }
        else {
            $("#tjMess").attr("disabled", "disabled");
            $("#ctl00_MainContent_HiddenField1").val($("#chaoMessage").val());
            __doPostBack('ctl00$MainContent$btnAdd', '');
        }
    }
}
function closewin() {
    window.parent.ymPrompt.close();
    $("#chaoMessage").val("");
    $("#ctl00_MainContent_btnAdd").removeAttr("disabled");
}
function popWin(Title) {
    var str = "<table style=\"height:210px;width:350px;border-collapse: collapse\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tr><td style=\"height:35px;\" class=\"PageList_Title\"><font color=\"black\">超时原因</font></td></tr><tr><td style=\"height:150px;\" class=\"TdContentC\">";
    str = str + "<textarea id=\"chaoMessage\" rows=\"5\" cols=\"20\" title=\"长度不能大于100个字或字符\" class=\"TextBoxStyle_multi\" length=\"100\" style=\"height:145px;width:98%;\"></textarea></td></tr>";
    str = str + "<tr><td style=\"height:25px;\" align=\"left\"><br/><font color=\"red\">注：</font><font color=\"black\">文书录入日期超过检查日期3个工作日时,需填写超时原因</font></td></tr><tr><td style=\"height:30px;\" align=\"center\"><br/><input type=\"button\" value=\" 保 存 \" class=\"ButtonStyleQD\" onclick=\"postform()\" id=\"tjMess\"/>&nbsp;&nbsp;<input type=\"button\" value=\" 关 闭 \" class=\"ButtonStyle\" onclick=\"closewin()\"/></td></tr></table>";
    ymPrompt.win({ message: '<div align=\"center\">' + str + '</div>', width: 380, height: 295, title: Title, handler: handler });
    $("#chaoMessage").val($("#ctl00_MainContent_HiddenField1").val());
    return false;
}
function handler() {
    $("#chaoMessage").val("");
    $("#ctl00_MainContent_btnAdd").removeAttr("disabled");
}
/*function ajaxyzwh() {
    var str = $("#ctl00_MainContent_HiddenField3").val().toString().split("|");
    var SSJG = str[0];
    var SSDW = str[1];
    var WSLB = str[2];
    var url = location.href;
    var ItemBH = "";
    var parstring = url.substring(url.indexOf("?") + 1, url.length).split("&");
    for (var i = 0; i < parstring.length; i++) {
        if (parstring[i].split("=")[0] == "ItemBH") {
            ItemBH = parstring[i].split("=")[1];
        }
    }
    var wh1 = "";
    var wh2 = "";
    var wh3 = $("#ctl00_MainContent_FLWSHead_txtYear").val();
    var wh4 = $("#ctl00_MainContent_FLWSHead_txtLSH").val();
    //修改文号判定
    var oldwh4 = $("#ctl00_MainContent_FLWSHead_hidOldwh4").val();
    var FlwsID = str[4];
    $.getJSON("../../JDJCPage/BACCPage/AjaxHandler.ashx", { 'FlwsID': FlwsID, 'SSJG': SSJG, 'SSDW': SSDW, 'ItemBH': ItemBH, 'WSLB': WSLB, 'wh2': wh2, 'wh3': wh3, 'wh4': wh4, 'oldwh4': oldwh4 }, function(json) {
        if (json.Result != "") {
            $("#ctl00_MainContent_btnAdd").removeAttr("disabled");
            alert(json.Result);
        }
        else {
            __doPostBack('ctl00$MainContent$btnAdd', '');
        }
    });
}*/